<!--自己添加的,注册功能-->
<template>
    <div id="register">
        <div class="bg"></div>
        <el-row class="main-container">
            <el-col :lg="8" :xs="16" :md="10" :span="10">
                <div class="top">
                    <i class="iconfont icon-kaoshi"></i><span class="title">在线考试系统</span>
                </div>
                <div class="bottom">
                    <div class="container">
                        <p class="title">账号注册</p>
                        <el-form :label-position="labelPosition" label-width="800px" :model="formLabelAlign">

                            <!-- 学生对话框 -->
                            <el-button type="primary" @click="dialogFormVisible1 = true">我是学生</el-button>

                            <el-dialog title="请填写学生信息" :visible.sync="dialogFormVisible1">
                                <el-form ref="form" :model="form" label-width="80px" style="display: inline-block;">
                                    <el-form-item label="姓名">
                                        <el-input v-model="form.studentName"></el-input>
                                    </el-form-item>
                                    <el-form-item label="性别">
                                        <el-input v-model="form.sex"></el-input>
                                    </el-form-item>
                                    <el-form-item label="学院">
                                        <el-input v-model="form.institute"></el-input>
                                    </el-form-item>
                                    <el-form-item label="所属专业">
                                        <el-input v-model="form.major"></el-input>
                                    </el-form-item>
                                    <el-form-item label="年级">
                                        <el-input v-model="form.grade"></el-input>
                                    </el-form-item>
                                    <el-form-item label="班级">
                                        <el-input v-model="form.clazz"></el-input>
                                    </el-form-item>
                                    <el-form-item label="电话号码">
                                        <el-input v-model="form.tel"></el-input>
                                    </el-form-item>
                                    <el-form-item label="身份证号">
                                        <el-input v-model="form.cardId"></el-input>
                                    </el-form-item>
                                    <el-form-item label="邮箱">
                                        <el-input v-model="form.email"></el-input>
                                    </el-form-item>
                                    <el-form-item label="密码">
                                        <el-input v-model="form.pwd"></el-input>
                                    </el-form-item>
                                    <el-form-item>
                                        <el-button type="primary" @click="onSubmit1()">立即创建</el-button>
                                        <el-button type="text" @click="canceldata()">取消</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-dialog>


                            <!-- 老师对话框 -->
                            <el-button type="primary" @click="dialogFormVisible2 = true">我是老师</el-button>

                            <el-dialog title="请填写老师信息" :visible.sync="dialogFormVisible2">
                                <el-form ref="form" :model="form" label-width="80px">
                                    <el-form-item label="姓名">
                                        <el-input v-model="form.teacherName"></el-input>
                                    </el-form-item>
                                    <el-form-item label="学院">
                                        <el-input v-model="form.institute"></el-input>
                                    </el-form-item>
                                    <el-form-item label="性别">
                                        <el-input v-model="form.sex"></el-input>
                                    </el-form-item>
                                    <el-form-item label="电话号码">
                                        <el-input v-model="form.tel"></el-input>
                                    </el-form-item>
                                    <el-form-item label="邮箱">
                                        <el-input v-model="form.email"></el-input>
                                    </el-form-item>
                                    <el-form-item label="身份证号">
                                        <el-input v-model="form.cardId"></el-input>
                                    </el-form-item>
                                    <el-form-item label="职称">
                                        <el-input v-model="form.type"></el-input>
                                    </el-form-item>
                                    <el-form-item label="密码">
                                        <el-input v-model="form.pwd"></el-input>
                                    </el-form-item>
                                    <el-form-item>
                                        <el-button type="primary" @click="onSubmit2()">立即创建</el-button>
                                        <el-button type="text" @click="canceldata()">取消</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-dialog>


                            <!-- 取消按钮 -->
                            <el-button type="danger" class="row-cancel" @click="cancelRegister()">取消注册</el-button>
                        </el-form>
                    </div>
                </div>
            </el-col>
        </el-row>

        <el-row class="footer">
            <el-col>
                <p class="msg2">如存在问题,可联系管理员: 1552951165(QQ)</p>
            </el-col>
        </el-row>
    </div>
</template>
    
<script>
import { mapState } from 'vuex'
export default {
    data() {
        return {
            dialogTableVisible: false,
            dialogFormVisible1: false,
            dialogFormVisible2: false,
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            formLabelWidth: '120px',
            role: '',
            labelPosition: 'left',
            formLabelAlign: {
                username: '',
                password: ''
            },
            form: { //表单数据初始化
                studentName: null,
                grade: null,
                major: null,
                clazz: null,
                institute: null,
                tel: null,
                email: null,
                pwd: null,
                cardId: null,
                sex: null,
                role: 2
            }
        };
    },
    methods: {
        clickTag(key) {
            this.role = key
        },

        goToFindPasswordPage() {
            this.$router.push('/find-password');
        },
        goToRegisterPage() {
            this.$router.push('/register');
        },
        cancelRegister() { //取消注册按钮
            this.$router.push({ path: '/' })
        },
        canceldata() { //取消按钮
            this.form = {}
            this.dialogFormVisible1 = false
            this.dialogFormVisible2 = false
        },
        onSubmit1() { //学生数据提交
            this.$axios({
                url: '/api/student',
                method: 'post',
                data: {
                    ...this.form
                }
            }).then(res => {
                if (res.data.code == 200) {
                    this.$message({
                        message: res.data.message,
                        type: 'success'
                    })
                    this.$router.push({ path: '/registerSuccess', query:{studentId: res.data.data.studentId,pwd: res.data.data.pwd} })
                } else {
                    this.$message({
                        message: res.data.message,
                        type: 'fail'
                    })
                }
            })
        },
        onSubmit2() { //老师数据提交
            this.$axios({
                url: '/api/teacher',
                method: 'post',
                data: {
                    ...this.form
                }
            }).then(res => {
                if (res.data.code == 200) {
                    this.$message({
                        message: res.data.message,
                        type: 'success'
                    })
                    this.$router.push({ path: '/registerSuccess',query:{teacherId:res.data.data.teacherId,pwd:res.data.data.pwd}})
                } else {
                    this.$message({
                        message : res.data.message,
                        type: 'fail'
                    })
                } 
            })
        },
        cancel() { //取消按钮
            this.form = {}
            this.$router.push({ path: '/register' })
        },

    },
    computed: mapState(["userInfo"]),
    mounted() {

    }

};
</script>
<style lang="less" scoped>
.remind {
    border-radius: 4px;
    padding: 10px 20px;
    display: flex;
    position: fixed;
    right: 20px;
    bottom: 50%;
    flex-direction: column;
    color: #606266;
    background-color: #fff;
    border-left: 4px solid #409eff;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}

.container {
    margin-bottom: 32px;
}

.container .el-radio-group {
    margin: 30px 0px;
}

a:link {
    color: #ff962a;
    text-decoration: none;
}

#register {
    font-size: 14px;
    color: #000;
    background-color: #fff;
}

#register .bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    overflow-y: auto;
    height: 100%;
    background: url('../../assets/img/loginbg.png')center top / cover no-repeat;
    background-color: #b6bccdd1 !important;
}

#register .main-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

#register .main-container .top {
    margin-top: 100px;
    font-size: 30px;
    color: #ff962a;
    display: flex;
    justify-content: center;
}

#register .top .icon-kaoshi {
    font-size: 80px;
}

#register .top .title {
    margin-top: 20px;
}

#register .bottom {
    display: flex;
    justify-content: center;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

#register .bottom .title {
    text-align: center;
    font-size: 30px;
}

.bottom .container .title {
    margin: 30px 0px;
    ;
}

.bottom .submit .row-register {
    width: 100%;
    background-color: #04468b;
    border-color: #04468b;
    margin: 20px 0px 10px 0px;
    padding: 15px 20px;
}

.bottom .submit .row-cancel {
    width: 100%;
    margin: 20px 0px 10px 0px;
    padding: 15px 20px;
}

.bottom .submit {
    display: flex;
    justify-content: center;
}

.footer {
    margin-top: 50px;
    text-align: center;
}

.footer .msg1 {
    font-size: 18px;
    color: #fff;
    margin-bottom: 15px;
}

.footer .msg2 {
    font-size: 14px;
    color: #673232;
    margin-top: 70px;
}

.bottom .options {
    margin-bottom: 40px;
    color: #ff962a;
    display: flex;
    justify-content: space-between;
}

.bottom .options>a {
    color: #ff962a;
}

.bottom .options .register span:nth-child(1) {
    color: #8C8C8C;
}

.add {
    padding: 0px 850px;
    width: 100%;
}
</style>